;
const food_index_ops = {
    init:function(){
        this.eventBind();
    },
    eventBind:function(){
        const that = this;
        $(".remove").click( function(){
            that.ops( "remove",$(this).attr("data") )
        });

        $(".recover").click( function(){
            that.ops( "recover",$(this).attr("data") )
        });

        $(".wrap_search .search").click( function(){
            $(".wrap_search").submit();
        });
    },
    ops:function( act,id ){
        const callback = {
            'ok':function(){
                $.ajax({
                    url: common_ops.buildUrl("/food/ops"),
                    type: 'POST',
                    data:{
                        act: act,
                        id: id
                    },
                    dataType: 'json',
                    success:function( res ){
                        let callback = null;
                        if ( res.code === 200 ) {
                            callback = function () {
                                window.location.href = window.location.href;
                            }
                        }
                        common_ops.alert( res.msg,callback );
                    }
                });
            },
            'cancel': null
        };
        common_ops.confirm( ( act=="remove" )?"确定删除？":"确定恢复？",callback );
    }
};

$(document).ready( function(){
    food_index_ops.init();
});